package com.wdc.stack;

import java.util.ArrayList;
import java.util.Stack;

public class E01Leetcode20 {

    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();

        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
           if (c == '('){
               stack.push(')');
           } else if (c == '{') {
               stack.push('}');
           } else if (c == '[') {
               stack.push(']');
           }else {
               if (!stack.isEmpty() && c == stack.peek() ){
                   stack.pop();
               }else {
                   return false;
               }
           }
        }

       return stack.isEmpty();


    }
}
